<nav id ="navbar" th:fragment="navbar" class="navbar navbar-default ">
    <div class="pb-container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
							<span class="sr-only">
								导航
							</span>
                <span class="icon-bar">
							</span>
                <span class="icon-bar">
							</span>
                <span class="icon-bar">
							</span>
            </button>
            <a class="logo-a" th:href="@{/}">
                <img th:src="@{/img/logo.png}" alt="logo">
            </a>
        </div>
        <div class="collapse navbar-collapse navbar-right" aria-expanded="false">
            <ul class="nav navbar-nav">
                <li th:class="${categoryId=='index' ? 'active' : ''} ">
                    <a th:href="@{/}".
                    >
                        首页
                    </a>
                </li>

                <li class="">
                    <a th:href="@{/order/myOrder}" th:if="${user != null}">
                        我的订单
                    </a>
                </li>
                <li class="" th:if="${user == null}">
                    <a th:href="@{/front/login}">
                        登录
                    </a>
                </li>
                <li class="dropdown user user-menu" th:if="${user != null}">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                        <span th:text="${user.username}"></span>
                    </a>
                    <ul class="dropdown-menu dropdown-left">
                        <li><a  href="/address">我的收货地址</a></li>
                        <li><a id="changePasswordBtn" href="#" data-toggle="modal" data-target="#passwordModal">修改密码</a></li>
                        <li class="divider"></li>
                        <li><a id="logoutBtn" href="#">注销用户</a></li>
                    </ul>
                </li>
            </ul>
        </div>
        <div id="passwordModal" class="modal fade" tabindex="-1" role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title">修改密码</h4>
                    </div>
                    <div class="modal-body">
                        <div>
                            <form class="form-horizontal" id="passwordForm">
                                <div class="box-body">
                                    <div class="form-group">
                                        <label for="oldPassword" class="col-sm-3 control-label">旧密码 :</label>
                                        <div class="col-sm-8">
                                            <input type="password" class="form-control" name="oldPassword" id="oldPassword" require="必填项"  placeholder="">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="password" class="col-sm-3 control-label">新密码 :</label>
                                        <div class="col-sm-8">
                                            <input type="password" class="form-control" name="newPassword" id="password" password="" pwdCheck="" require="必填项"  placeholder="">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="confirmPassword" class="col-sm-3 control-label">确认新密码 :</label>
                                        <div class="col-sm-8">
                                            <input type="password" class="form-control" name="confirmNewPassword" id="confirmPassword" password=""  require="必填项" placeholder="">
                                        </div>
                                    </div>

                                </div>
                                <!-- /.box-body -->
                                <div class="box-footer">
                                    <div class="pull-right">
                                        <button type="button" id="savePassword" class="btn btn-info">确定</button>
                                        <button type="button" data-dismiss="modal" class="btn btn-default">取消</button>
                                    </div>
                                </div>
                                <!-- /.box-footer -->
                            </form>
                        </div>
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div>
    </div>
    <script>
        $(function () {
            //修改信息
            $("#userInfoBtn").on('click', function () {
                Core.load("#myInfoOpenWindow","/front/user/edit?userId="+$("#userId").text(), function(){
                    $("#myModal").modal("show");
                });
            })
            /*退出登录*/
            $("#logoutBtn").on('click', function () {
                Core.confirm("确认退出？",function () {
                    Core.postAjax("/logout",{},function(data){
                        if(data.status==200){
                            window.location.href = (ctx + "/front/login").replace('//', '/');
                        }else{
                            layer.msg(data.msg);
                        }
                    })
                })
            })
            /*修改密码*/
            $("#changePasswordBtn").on('click', function () {
                $("#passwordForm")[0].reset();
                Core.clearError("#passwordForm");
            })
            /*确定修改密码*/
            $("#savePassword").on('click', function () {
                if(doValidForm(passwordForm)){
                    Core.mask("#savePassword")
                    Core.postAjax("/user/changePassword",$("#passwordForm").serialize(),function(data){
                        Core.unmask("#savePassword")
                        if(data.status==200){
                            $("#passwordModal").modal("hide");
                            layer.msg('密码修改成功!');
                            window.location.href = (ctx + "/front/login").replace('//', '/');
                        }else{
                            layer.msg(data.msg);
                        }
                    })
                }
            })

            $("#passwordForm").keyup(function(event){
                if(event.keyCode ==13){
                    $("#savePassword").click();
                }
            });
        });
    </script>
</nav>